package cn.touna.jss.modules.third.xinyan.enums;

import org.apache.commons.lang.StringUtils;

import java.util.Arrays;

/**
 ********************************************************
 * 新颜接口错误码枚举类
 * @author zhangjialian
 * @Date 2018-08-14 16:06
 * @Version V1.0
 ********************************************************/
public enum XinyanErrorCodeEnum {
    SYSTEM_IS_BUSY("S0001", "系统繁忙，请稍后再试"),
    PARAMS_REQ_ERROR("S1000", "请求参数有误（具体以响应参数错误为准）"),
    REQ_ORDER_NOT_EXIST("S1001", "请求订单不存在或已过期，请重新发起交易"),
    ORDER_BEING_PROCESSED("S1002", "请求订单已受理，请稍后查询交易结果"),
    ORDER_CREADED_FAILED("S1004", "请求订单创建失败"),
    REQ_PACJET_PARSE_FAILED("S1005", "请求报文解析失败"),
    ORDER_PROCESS_FAILED("S1006", "请求报文加密数据处理失败"),
    DATA_NOT_MATCH("S1007", "请求明文数据与密文数据不一致"),
    MERCHANT_NOT_EXIST("S2000", "商户不存在"),
    MERCHANT_STATUS_EXCEPTION("S2001", "商户状态异常"),
    MERCHANT_INFO_NOT_EXIST("S2002", "商户终端信息不存在"),
    MERCHANT_INFO_STATUS_EXCEPTION("S2003", "商户终端信息状态异常"),
    MERCHANT_NOT_SUPPORT_THIS_PROD("S2004", "商户暂不支持该产品"),
    MERCHANT_NOT_SUPPORT_THIS_FUNC("S2005", "商户暂不支持该功能"),
    MERCHANT_INSUFFICIENT_BALANCE("S2006", "商户余额不足"),
    ;

    XinyanErrorCodeEnum(String code, String name) {
        this.code = code;
        this.name = name;
    }

    public static XinyanErrorCodeEnum getByCode(String code){
        if(StringUtils.isEmpty(code)){return null;}
        return Arrays.stream(XinyanErrorCodeEnum.values()).filter(e->e.getCode().equals(code)).findFirst()
                .orElse(null);
    }

    private String code;
    private String name;

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

//    public static void main(String[] args) {
//        System.out.println(XinyanErrorCodeEnum.getByCode("-9001").getName());
//    }
}
